const CONFIG = require('../../config.js');

let TEXTData;
Page({
	data: {
		navBgColor: '-webkit-gradient(linear, 0% 0%, 0% 100%,from(#1b64e5), to(#488dea))',
		B003Value: [1],
		loginInfo:'',
		baseImg: '',
		persentNum: '',
		TEXTDataList: [],
	},

	// 用户评分接口
	setScoreData(){
		wx.request({
			url: CONFIG.host + "system/appRiskInfoController/riskUser",
			data: {},
			method: "GET",
			header: {
				'content-type': 'application/json',
				'Authorization': this.data.loginInfo.token
			},
			success: res => {
				if(res.data.code === 'success'){
					this.getUserScoreData();
				}else{
					wx.showToast({
						title: res.data.message || '数据错误！',
						icon: 'none',
						duration: 4000
					})
				}
			},fail: function (error) {
				console.log(error);
			}
		})
	},

	// 获取用户评分
	getUserScoreData(){
		wx.request({
			url: CONFIG.host + "system/appRiskInfoController/getRiskUserInfo",
			data: {},
			method: "GET",
			header: {
				'content-type': 'application/json',
				'Authorization': this.data.loginInfo.token
			},
			success: res => {
				if(res.data.code === 'success'){
					this.setData({
						userScore: res.data.data.riskInfo,
						persentNum: res.data.data.percent,
						baseImg: '../../images/score-' + res.data.data.riskInfo.grade + '.jpg'
					})
				}
			},fail: function (error) {
				console.log(error);
			}
		})
	},


	onLoad: function () {
		let showNum = wx.getStorageSync('showUser') === '0' ? '0' : '1';
		TEXTData = require('../../utils/text'+ showNum +'.js');
		TEXTData = TEXTData.textJson;
		let loginInfo = wx.getStorageSync('loginInfo') || '';
		if(loginInfo){
			this.setData({
				loginInfo: JSON.parse(loginInfo),
				TEXTDataList: TEXTData
			})
			this.setScoreData();
		}
	}
})
